<?php
// +----------------------------------------------------------------------
// | InitHookBehavior.
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.abc3210.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: wjf <admin@abc3210.com> 2017/6/26
// +----------------------------------------------------------------------

namespace wjf\behavior;

use think\Db;
use think\Hook;

class InitHookBehavior
{
    //行为扩展的执行入口必须是run
    public function run(&$param)
    {
        if (!wjf_is_installed()) {
            return;
        }

        $plugins = Db::name('hook_plugin')
            ->field('hook,plugin')
            ->where('status', 1)
            ->order('list_order ASC')
            ->select();

        if (!empty($plugins)) {
            foreach ($plugins as $hookPlugin) {
                Hook::add($hookPlugin['hook'], wjf_get_plugin_class($hookPlugin['plugin']));
            }
        }
    }
}